/**
 * Created by ����Ӱ�� on 2018/8/8.
 */
//$(function () {

//getId();

//xuanfaAjax(2, "1C57D351-6D36-0357-EC7F-F6E8426302E5")

var isMobile = ismobile();

if (isMobile == 0) {

    //alert("lllll")

    window.android.getAndroidId("okok");
}

function WebViewDidFinishLoad() {

    var message = {

        "VcWay": "SendId"
    };

    window.webkit.messageHandlers.CallDiffusionDetailsModel.postMessage(message);
}


//});

function ismobile() {
    //判断访问终端
    var browser = {
        versions: function () {
            var u = navigator.userAgent, app = navigator.appVersion;
            return {
                trident: u.indexOf('Trident') > -1, //IE内核
                presto: u.indexOf('Presto') > -1, //opera内核
                webKit: u.indexOf('AppleWebKit') > -1, //苹果、谷歌内核
                gecko: u.indexOf('Gecko') > -1 && u.indexOf('KHTML') == -1,//火狐内核
                mobile: !!u.match(/AppleWebKit.*Mobile.*/), //是否为移动终端
                ios: !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/), //ios终端
                android: u.indexOf('Android') > -1 || u.indexOf('Adr') > -1, //android终端
                iPhone: u.indexOf('iPhone') > -1, //是否为iPhone或者QQHD浏览器
                iPad: u.indexOf('iPad') > -1, //是否iPad
                webApp: u.indexOf('Safari') == -1, //是否web应该程序，没有头部与底部
                weixin: u.indexOf('MicroMessenger') > -1, //是否微信 （2015-01-22新增）
                qq: u.match(/\sQQ/i) == " qq" //是否QQ
            };
        }(),
        language: (navigator.browserLanguage || navigator.language).toLowerCase()
    };

    if (browser.versions.mobile == true) {
        if (browser.versions.iPhone == true) {
            return '1';
        } else if (browser.versions.android == true) {
            return '0';
        }
    } else {

    }
}


function getId() {

    if (isMobile == 1) {

        CallDiffusionDetailsModel.jsCallOCWithSendId()

    } else if (isMobile == 0) {

        window.android.getAndroidId("okok");
    }
}

function receiveAndroidDetail(i) {

    var obj = $.parseJSON(i);

    xuanfaAjax(obj.team_id, obj.TOKEN, obj.belong_model);

}

function receiveiOSVcData(i) {

    var obj = $.parseJSON(i);

    xuanfaAjax(obj.team_id, obj.TOKEN, obj.belong_model);

}

function xuanfaAjax(teamId, token, belong_model) {

    $.ajax({

        type: "POST",

        url: url + "common",

        data: {

            "team_id": teamId,

            "belong_model": belong_model
        },
        beforeSend: function (xhr) {

            xhr.setRequestHeader("CUSTOM-URL", "v1/fourModel/makeTeamInfoWeb");

            xhr.setRequestHeader("TOKEN", token)

        },

        dataType: "json",

        success: function (data) {

            console.log(data);

            if (data.codes == 200) {

                //data.data.caseInfo.length=3;

                var html = template("teamDetailTpl", data);

                $(".container").html(html);

                $(".sub").on("click", function () {//点击提交需求

                    var json = {"id": data.data.team_id};

                    if (isMobile == 1) {

                        var message = {

                            "VcData": json,

                            "VcName": "DiffusionNewRelease",

                            "VcWay": "PushVCName"
                        };

                        window.webkit.messageHandlers.CallDiffusionDetailsModel.postMessage(message);

                    } else if (isMobile == 0) {

                        window.android.jumpToDispersingConmitDemand(JSON.stringify(json))

                    }


                });

                if (isiphoneX) {

                    $(".footer_position").addClass("footer")

                } else {

                    $(".footer_position").removeClass("footer")
                }


                if (data.data.caseInfo.length > 0) {

                    var caseUlWidth = data.data.caseInfo.length * 4.27 + "rem";

                    $("#ul").css("width", caseUlWidth);

                } else {

                    $("#ul").css("width", 100 + "%");
                }

            }
            //轮播
            new Swiper('.swiper-container', {

                direction: 'horizontal',

                loop: true,

                autoplay: 2000,

                // 如果需要分页器

                pagination: '.swiper-pagination',

                autoplayDisableOnInteraction: false
            });

            clickCase(token);
        },
        error: function (info) {

            console.log(info)
        }
    });
}

function clickCase(token) {

    $("#ul").on("click", "li", function () {


        var id = $(this).attr("id");

        if (!id) return false;

        var json = {

            "title": '制作案例详情',

            "url": 'https://viewapi.aipics.cn/view_h5/four_plates/make/makeDetail.html',

            "team_id": id,

            "TOKEN": token,

            "CallModelName": "CallFabricationDetailsModel"
        };


        if (isMobile == 1) {

            var message = {

                "VcData": json,

                "VcName": "PublicWeb",

                "VcWay": "PushVCName"
            };

            window.webkit.messageHandlers.CallDiffusionDetailsModel.postMessage(message);

        } else if (isMobile == 0) {


            window.android.jumpToProjectFourModelDetail(JSON.stringify(json));

        }

    })
}